package com.example.code.controller;

import com.example.code.Constant;
import com.example.code.vo.GeneralContentResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Slf4j
@RestController
@RequestMapping(value = "c_d")
@Tag(name = "接口示例")
public class DemoAction {

    @Operation(summary="获取当前时间")
    @RequestMapping(value = "get_now_time", method = RequestMethod.GET)
    public GeneralContentResult getNowTime(HttpServletRequest request,
                                              @RequestParam(value = "str") String str) throws Exception {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss SSS");

        return new GeneralContentResult(Constant.ResultCode.SUCCESS.getVal(), "",
                String.format("Hello %s, 当前时间是：%s",str, formatter.format(LocalDateTime.now())));
    }

}
